﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Automation.Peers;

namespace FinPlusWPFControls
{
    public class IsGreaterThanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || value.Equals(string.Empty)) return false;

            var dValue = System.Convert.ToDouble(value);
            var dParameter = System.Convert.ToDouble(parameter);

            return (dValue >= dParameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    public class PercentageConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var height = 0.0;
            double.TryParse(values[0].ToString(), out height);

            var control = (System.Windows.Controls.DataVisualization.Charting.LinearAxis)values[1];

            return control.ActualHeight * height / (control.ActualMaximum - control.ActualMinimum) ;

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
